package org.easymis.portal.modules.main.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.easymis.commons.web.utils.StringUtils;
import org.easymis.portal.modules.main.entitys.mybatis.dto.AppletTemplate;
import org.easymis.portal.modules.main.entitys.mybatis.dto.AppletTemplateCategory;
import org.easymis.portal.modules.main.service.AppletMng;
import org.easymis.portal.modules.main.service.AppletTemplateCategoryMng;
import org.easymis.portal.modules.main.service.AppletTemplateMng;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/applet/")
public class AppletAction {
	public static final String INDEX = "applet/index";
	public static final String DETAIL = "applet/detail";
	@Autowired
	private AppletMng appletMng;
	@Autowired
	private AppletTemplateMng appletTemplateMng;
	@Autowired
	private AppletTemplateCategoryMng categoryMng;
	
	@RequestMapping(value = "index.html", method = RequestMethod.GET)
	public String input(HttpServletRequest request, HttpServletResponse response, ModelMap model, HttpSession session) {
		String authenticityToken = StringUtils.makeUUID();
		model.put("authenticityToken", authenticityToken);
		session.setAttribute("authenticityToken", authenticityToken);
		 List<AppletTemplateCategory> categoryList=categoryMng.getList( new AppletTemplateCategory());
		 List<AppletTemplate> appletTemplateList=appletTemplateMng.getList(new AppletTemplate());
		
		 model.put("categoryList", categoryList);
		 model.put("appletTemplateList", appletTemplateList);
		 request.setAttribute("base", "http://www.easymis.cn");
		return "index";
	}
	@RequestMapping(value = "view.html", method = RequestMethod.GET)
	public String view(HttpServletRequest request, HttpServletResponse response, ModelMap model, HttpSession session) {
		String authenticityToken = StringUtils.makeUUID();
		model.put("authenticityToken", authenticityToken);
		session.setAttribute("authenticityToken", authenticityToken);
		 List<AppletTemplateCategory> categoryList=categoryMng.getList( new AppletTemplateCategory());
		
		 model.put("categoryList", categoryList);
		 request.setAttribute("base", "http://www.easymis.cn");
		return "applet/detail";
	}
}
